package com.yunmaozj.tools.lock.annotations;

import com.yunmaozj.tools.lock.RedisLock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportAware;
import org.springframework.core.annotation.AnnotationAttributes;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.lang.Nullable;
import org.springframework.util.CollectionUtils;

/**
 * @author 钟明宏
 * @version V1.0
 * @date 2021-08-29 21:10
 **/
@Configuration
public abstract class AbstractDistributedLockConfiguration implements ImportAware {
    @Nullable
    protected AnnotationAttributes enableDL;

    @Nullable

    @Override
    public void setImportMetadata(AnnotationMetadata importMetadata) {
        this.enableDL = AnnotationAttributes.fromMap(
                importMetadata.getAnnotationAttributes(EnableDistributedLock.class.getName(), false));
        if (this.enableDL == null) {
            throw new IllegalArgumentException("@DistributedLock is not present on importing class " + importMetadata.getClassName());
        }
    }
}
